<?php

require_once 'TestCase.php';

class tView_TestSuite {
	
	const TYPE_PASSED	= 'passed';
	const TYPE_EMPTY	= 'empty';
	const TYPE_ERROR	= 'error';
	const TYPE_FAILED	= 'failed';
	
	protected $_name;
	protected $_file;
	protected $_tests;
	protected $_assertions;
	protected $_failures;
	protected $_errors;
	protected $_time;
	
	protected $_testCases = array();
	
	public function __construct($testSuite) {
		$this->_name = (string)$testSuite['name'];
		$this->_file = (string)$testSuite['file'];
		$this->_tests = (int)$testSuite['tests'];
		$this->_assertions = (int)$testSuite['assertions'];
		$this->_failures = (int)$testSuite['failures'];
		$this->_errors = (int)$testSuite['errors'];
		$this->_time = (float)$testSuite['time'];
	}
	
	public function isEmpty() {
		return $this->_tests == 0;
	}
	
	public function addTestCase($testCase) {
		$this->_testCases[] = new tView_TestCase($testCase);
	}
	
	public function getTestCases() {
		return $this->_testCases;
	}
	
	public function getFailedTestCases() {
		$res = array();
		foreach ($this->_testCases as $testCase) {
			if (self::TYPE_FAILED == $testCase->getType()) {
				$res[] = $testCase;
			}
		}
		return $res;
	}
	
	public function getName() {
		return $this->_name;
	}
	
	public function getFile() {
		return $this->_file;
	}
	
	public function getTime() {
		return $this->_time;
	}
	
	public function getCount() {
		if (0 == $this->_tests) {
			return 1;
		}
		return $this->_tests;
	}
	
	public function getAssertions() {
		return $this->_assertions;
	}
	
	public function getType() {
		if (0 == $this->_tests) {
			return self::TYPE_EMPTY;
		}
		if ($this->_errors > 0) {
			return self::TYPE_ERROR;
		}
		if ($this->_failures > 0) {
			return self::TYPE_FAILED;
		}
		return self::TYPE_PASSED;
	}
	
}
